package com.ruoyi.project.system.home.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.project.system.dict.utils.DictUtils;
import com.ruoyi.project.system.home.domain.*;
import com.ruoyi.project.system.home.mapper.MiniBaseFamilyMapper;
import com.ruoyi.project.system.home.service.MiniIBaseFamilyService;
import com.ruoyi.project.system.home.utils.PageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class MiniBaseFamilyServiceImpl implements MiniIBaseFamilyService {

    @Autowired
    private MiniBaseFamilyMapper baseFamilyMapper;


    @Override
    public MiniPageResult getAllUserByPage(MiniPageRequest pageRequest) {
        return PageUtils.getPageResult(getPageInfo(pageRequest));
    }

    @Override
    public Integer getDataSize() {
        return baseFamilyMapper.getDataSize();
    }


    private PageInfo<MiniBaseFamilyInfoS> getPageInfo(MiniPageRequest pageRequest) {
        int pageNum = pageRequest.getPageNum();
        int pageSize = pageRequest.getPageSize();
        Page<Object> objects = PageHelper.startPage(pageNum, pageSize);
        List<MiniBaseFamilyInfoS> allUserByPage = baseFamilyMapper.getAllUserByPage();
        for (MiniBaseFamilyInfoS miniBaseFamilyInfo : allUserByPage) {
            String base_nature_village = DictUtils.getDictLabel("base_nature_village", String.valueOf(miniBaseFamilyInfo.getNat_village()));
            miniBaseFamilyInfo.setVillage(base_nature_village);
        }
        return new PageInfo<MiniBaseFamilyInfoS>(allUserByPage);
    }


    /**
     * 搜索功能
     */
    @Override
    public List<MiniBaseFamilyInfoS> selectBaseFamilySearch(String searchContent) {
        return baseFamilyMapper.selectBaseFamilySearch(searchContent);
    }



    @Override
    public MiniBaseFamilyInfoS getShowUserByFid(String fid,int reportYear) {
        return baseFamilyMapper.getShowUserByFid(fid,reportYear);
    }

    @Override
    public List<MiniBaseFamilyInfoS> selectBaseFamilyListS() {
        return baseFamilyMapper.selectBaseFamilyListS();
    }

    @Override
    public List<MiniBaseFamilyInfoS> selectBaseFamilySearchByVillage(int natVillage) {
        return baseFamilyMapper.selectBaseFamilySearchByVillage(natVillage);
    }

}
